/**
 * 
 */

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import com.lowagie.text.Anchor;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.List;
import com.lowagie.text.ListItem;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.RomanList;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

/**
 * @author zhangmz
 *
 */
public class PDFDemo {
	//设置pdf页面大小 左右边距
	public static void test1(){
		//定义一个A4页面大小的文档
		Document document = new Document(PageSize.A4);
//		//设置页面 200 * 800 单位是用户显示单元，默认是1/72英寸。
//		Rectangle pageSize = new Rectangle(200f,800f);
//		//页边距，顺序是左右上下。
//		Document doc = new Document(pageSize,20f,20f,20f,20f);
		
		try {
			//创建一个pdf书写器
			PdfWriter pw = PdfWriter.getInstance(document, new FileOutputStream("D:\\test1.pdf"));
			document.open();//打开文档
			document.add(new Paragraph("Hello World!"));//输出一个pdf 内容
			document.close();//关闭文档
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
	}
	
	//设置Pdf页面背景颜色、文档属性
	public static void test2(){
		//定义一个A4大小的矩形组件
		Rectangle rect = new Rectangle(PageSize.A4);
		//设置背景色为浅灰色
		rect.setBackgroundColor(Color.LIGHT_GRAY);
		//设置border类型为box（四周都有）
		rect.setBorder(Rectangle.BOX);
		//设置border颜色为深灰色
		rect.setBorderColor(Color.DARK_GRAY);
		//设置border宽度为5
		rect.setBorderWidth(5);
		Document doc = new Document(rect);//设置好的Pdf样式导入并创建document
		
		try {
			PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream("d:\\test2.pdf"));
			//先设置文档信息
			doc.addTitle("标题");
			doc.addAuthor("作者");
			doc.addCreationDate();
			doc.addCreator("创建者");
			doc.addSubject("Subject");
			doc.addKeywords("KeyWords");
			doc.addHeader("Expires", "0");
			
			doc.open();//打开文档
			
			doc.add(new Paragraph("Hello World!"));//输出一个pdf内容
			
			doc.close();//关闭文档
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			e.printStackTrace();
		}
	}
	
	//一个简单的输出中文的实例、设置字体、所在位置等
	public static void test3(){
		Document doc = new Document(PageSize.A4);
		
		try {
			PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream("D:\\test3.pdf"));
			doc.open();
			
			BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//设置中文字体 font. 加字体
			
			Font fontChinese = new Font(bfChinese,16,Font.NORMAL);
			
			doc.add(new Paragraph("Hello World,Hello PDF Come On!!ADF"));
			//段落的设置属性 还有字体的添加
			Paragraph paragraph = new Paragraph("这里是中文",fontChinese);
			//居中显示 ALIGN_RIGHT，ALIGN_LEFT
			paragraph.setAlignment(Element.ALIGN_CENTER);
			// paragraph.setIndentationLeft(50f);//文本距左侧的绝对位置
			doc.add(paragraph);
			
			doc.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//实现外部链接
	public static void test4(){
		Document doc = new Document(PageSize.A4);
		
		try {
			//创建PDF
			PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream("D:\\test4.pdf"));
			doc.open();
			//链接内容
			Chunk chunk = new Chunk("Quick brown fox jumps over the lazy dog.");
			//链接地址
			chunk.setAnchor("http://www.baidu.com");
			doc.add(chunk);
			doc.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//实现内部链接 类似于Html 的#XXX
	public static void test5(){
		Document doc = new Document(PageSize.A4);
		try {
			PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream("d:\\test5.pdf"));
			doc.open();
			Paragraph paragraph = new Paragraph("Quick brown \n");
			Anchor foxReference = new Anchor("fox");
			//设置点击 fox 实现跳转
			foxReference.setReference("#fox");
			paragraph.add(foxReference);
			paragraph.add("  jumps over the lazy dog.  ");
			doc.add(paragraph);
			//新建一页
			doc.newPage();
			Anchor foxName = new Anchor("This is the FOX.");
			//必须和实现跳转的单词一样
			foxName.setName("fox");
			doc.add(foxName);
			doc.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//跳转到另一个pdf文件
	public static void test6(){
		Document doc = new Document(PageSize.A4);
		try {
			PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream("D:\\test6.pdf"));
			doc.open();
			Paragraph p1 = new Paragraph("The quick brown fox wants to");
			Chunk chunk = new Chunk(" jump over ");
			//可以链接其他pdf文档
			chunk.setRemoteGoto("d:\\hello.pdf", "jump");
			p1.add(chunk);
			p1.add(" the lazy dog. ");
			doc.add(p1);
			doc.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//设置PDF密码和权限(打印/拷贝),并设置加密类型
	public static void test7(){
		Document doc = new Document(PageSize.A4);
		try {
			PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream("d:\\test7.pdf"));
			/**
			 * 第一个参数是设置userPassword为123
			 * 第二个参数是设置ownerPassword为1234
			 * 第三个参数是设置user的权限可以复制、可以打印
			 * 第四个参数设置加密类型
			 */
			pw.setEncryption("123".getBytes(),"1234".getBytes(),PdfWriter.ALLOW_PRINTING|PdfWriter.ALLOW_COPY,PdfWriter.STANDARD_ENCRYPTION_40);
			doc.open();
			doc.add(new Paragraph("Hello World!!"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			doc.close();
		}
	}
	//这段代码有问题。
	public static void test8(){
		Document doc = new Document(PageSize.A4);
		try {
			PdfWriter pw = PdfWriter.getInstance(doc, new FileOutputStream("d:\\test8.pdf"));
			doc.open();
			//有序的20为字与符号之间的距离
			List list1 = new List(List.ORDERED,20); 
			list1.add(new ListItem("the lazy dog"));
			doc.add((com.lowagie.text.Element) list1);
			//无需的
			List list2 = new List(List.UNORDERED,10);
			list2.add(new ListItem("the lazy cat"));
			doc.add((com.lowagie.text.Element) list2);
			//设置特许符号 这个是字母 有序
			List list3 = new List(List.ORDERED,List.ALPHABETICAL,20);
			list3.add(new ListItem("the fence1"));
			list3.add(new ListItem("the fence2"));
			list3.add(new ListItem("the fence3"));
			doc.add((com.lowagie.text.Element) list3);
			//设置特许符号  -->
			List list4 = new List(List.UNORDERED,30);
			list4.setListSymbol("-->");
			//缩进多少
			list4.setIndentationLeft(10);
			list4.add("the lazy dog");
			doc.add((com.lowagie.text.Element) list4);    
			List list5 = new List(List.ORDERED, 20);
			//以11开始  12,13,14...  
			list5.setFirst(11);                
			list5.add(new ListItem("the lazy cat"));    
			doc.add((com.lowagie.text.Element) list5);    
			List list = new List(List.UNORDERED, 10);    
//			list.setListSymbol(new Chunk('*')); 
			list.setListSymbol("*");
			list.add(list1);     
			list.add(list3);     
			list.add(list5);     
			doc.add((com.lowagie.text.Element) list);     
			RomanList romanlist = new RomanList(20);     
			romanlist.add(new ListItem("the lazy dog"));     
			romanlist.add(new ListItem("the lazy dog"));     
			doc.add(romanlist);
			/*doc.add(new Paragraph("Hello World!!"));*/
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			doc.close();
		
	}
	//简单的表格及表格边框颜色
	public static void test9(){
		Document document=new Document(PageSize.A4);
		 try {
			 PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("d:\\test9.pdf"));
			 document.open();        
			 PdfPTable table = new PdfPTable(3);     //列数     
			 PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));   //表头信息    
			 cell.setColspan(3);     //表头列数    
			 table.addCell(cell);   
//			 第一行
			 table.addCell("1.1");    
			 table.addCell("2.1");    
			 table.addCell("3.1"); 
//			 第二行
			 table.addCell("1.2");    
			 table.addCell("2.2");    
			 table.addCell("3.2");  
//			 第三行
			 table.addCell("1.3");    
			 table.addCell("2.3");   
			 cell=new PdfPCell(new Paragraph("3.3"));//針對第三行添加紅色邊框
			 cell.setBorderColor(Color.red);   //设置边框颜
			 /*cell.setBorderWidthLeft(6f);        
			  * //设置表格边框样式和颜色      
			  * cell.setBorderWidthBottom(5f);     
			  *  cell.setBorderWidthRight(4f);      
			  *  cell.setBorderWidthTop(2f);      
			  *  cell.setBorderColorLeft(Color.red);      
			  *  cell.setBorderColorBottom(Color.orange);      
			  *  cell.setBorderColorRight(Color.yellow);      
			  *  cell.setBorderColorTop(Color.green);*/    
			 table.addCell(cell);    
			 document.add(table);     
			 document.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}     
	}
	//表的边框颜色表格列大小设置
	public static void test10(){
		Document document = new Document(PageSize.A4,50,50,50,50);
		try {
			PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("d:\\test10.pdf"));
			document.open();
			PdfPTable table = new PdfPTable(3);
			PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
			cell.setColspan(3); 
			cell.setHorizontalAlignment(Element.ALIGN_CENTER); //设置表头居中显示
			table.addCell(cell);
			table.addCell("1.1");
			table.addCell("2.1");
			table.addCell("3.1");
			table.addCell("1.2");
			table.addCell("2.2");
			table.addCell("3.2");
			float[] widths = {0.3f, 0.3f, 0.1f};
			 //设置列的宽度  百分比的形式
			table.setWidths(widths);  
			document.add(table);
			//页面的百分比
			table.setWidthPercentage(100);     
			document.add(table);           
			table.setWidthPercentage(50);
			//右对齐  
			table.setHorizontalAlignment(Element.ALIGN_RIGHT); 
			document.add(table);
			//左对齐  
			table.setHorizontalAlignment(Element.ALIGN_LEFT); 
			document.add(table);    
			//设置表格与表格之间的距离    
			table.setSpacingBefore(15f);       
			table.setSpacingAfter(10f);
			//设置表的绝对宽度 
			table.setTotalWidth(400);    
			table.setLockedWidth(true);          
			document.add(table);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			document.close();
		}
	}
	//嵌套表
	public static void test11(){
		Document document = new Document(PageSize.A4,50,50,50,50);
		try {
			PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("d:\\test11.pdf"));
			document.open();             
			PdfPTable table = new PdfPTable(4);             
			PdfPTable nested1 = new PdfPTable(2);             
			nested1.addCell("1.1");             
			nested1.addCell("1.2");             
			PdfPTable nested2 = new PdfPTable(1);             
			nested2.addCell("2.1");             
			nested2.addCell("2.2");             
			for (int k = 0; k < 24; ++k) {                 
				if (k == 1) {                     
					table.addCell(nested1);      //两列                
				}else if (k == 20) {                     
					table.addCell(nested2);      //一列                 
				}else{
					table.addCell("cell "+k);
				}                 
			}
			document.add(table);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		document.close();
	}
	//合并单元格
	public static void test12(){
		Document document = new Document(PageSize.A4, 36, 36, 36, 36);
		try {
			PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("d:\\test12.pdf"));
			document.open();         
			PdfPTable table = new PdfPTable(4);      // 最外层table     
			float[] wid = {80f, 100f, 80f, 60f};     
			table.setTotalWidth(wid);     
			table.setLockedWidth(true);                   
			PdfPCell cell = null;                    
			// 最外层table的cell                  
			PdfPTable iTable = null;                 
			// 嵌套的table
			PdfPCell iCell = null;                   // 嵌套的table的cell                  
			iTable = new PdfPTable(3);     
			float[] iWid = {80f, 100f, 80f};     
			iTable.setTotalWidth(iWid);     
			iTable.setLockedWidth(true);     
			iCell = new PdfPCell(new Paragraph("column 1"));     
			iCell.setFixedHeight(30);     
			iTable.addCell(iCell);     
			iCell.setColspan(2);     
			iTable.addCell(iCell);     
			iCell = new PdfPCell(new Paragraph("column 2"));     
			iCell.setFixedHeight(30);     
			iTable.addCell(iCell);     
			iTable.addCell(iCell);     
			iTable.addCell(iCell);     
			iCell = new PdfPCell(new Paragraph("column 3"));     
			iCell.setFixedHeight(30);     
			iTable.addCell(iCell);     
			iTable.addCell(iCell);     
			iTable.addCell(iCell);
			cell = new PdfPCell(iTable);                // 用这个table初始外层table的cell     
			cell.setColspan(3);                         // 设置它跨3列     
			// cell.setFixedHeight(10*10);  // 设置它的高度    
			table.addCell(cell);  // 将这个cell加入table中     
			iTable = new PdfPTable(1);       
			float[] iWid2 = {60f};     
			iTable.setTotalWidth(iWid2);     
			iTable.setLockedWidth(true);     
			iCell = new PdfPCell(new Paragraph("i am here"));     
			iTable.addCell(iCell);     
			cell = new PdfPCell(iTable);     
			// cell.setFixedHeight(3*30);  // 跨3列了     
			table.addCell(cell);         
			document.add(table);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			document.close();
		}
	}
	//单元格内数据显示实例
	public static void test13(){
		Document document=new Document(PageSize.A4);
		try {
			PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("d:\\test13.pdf"));
			document.open();        
			PdfPTable table = new PdfPTable(2);     //列数     
			PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));   //表头信息    
			cell.setColspan(3);     //表头列数    
			table.addCell(cell);    
			Paragraph p = new Paragraph("Quick brown fox jumps over the lazy dog asd fadsfasd faew fawe fawef " +    "awe fawea awe af aw efaw efae fae faw efaew fa wef aef.");    
			table.addCell("default alignment");    
			cell = new PdfPCell(p);    
			table.addCell(p);        
			table.addCell("centered alignment");    
			cell = new PdfPCell(p);
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell(cell);        
			table.addCell("right alignment");   
			cell = new PdfPCell(p);    
			cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
			table.addCell(cell);        
			table.addCell("lelt alignment");    
			cell = new PdfPCell(p);    
			cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);    
			table.addCell(cell);        
			table.addCell("blah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\n");    
			table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);    
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell("bottom");    //middle  top    
			document.add(table);        
			document.close();   
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}     
		document.close();
	}
	//简单的图片显示
	public static void test14(){
		Document document=new Document(PageSize.A4);
		try {
			PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("d:\\test14.pdf"));
			document.open();     
			Image img1 = Image.getInstance("d:\\qq.png"); //图片的位置   
			img1.setIndentationLeft(100f);     //设置绝对位置    
			document.add(img1);                               
			document.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//综合应用实例1：
	public static void test15(){
		Document document = new Document(PageSize.A4,10,10,36,36);
		try {
			PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("d:\\test15.pdf"));
			document.open();   
			BaseFont   bfChinese=BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);    
			Font  FontChinese=new  Font(bfChinese,18,Font.BOLD); //设置字体    
			Font FontData=new Font(bfChinese,12,Font.UNDEFINED);    
			Font FontTable=new Font(bfChinese,10,Font.NORMAL);    
			Font  FontTableHeader=new Font(bfChinese,8,Font.BOLD);    
			Paragraph  title=new  Paragraph("客户报价单",FontChinese);//修改客户报价单
			document.add(title);
			PdfPTable tableHeader = new PdfPTable(2);
			PdfPCell cell = new PdfPCell(new Paragraph("客户编号："+"03160564603216613",FontData));
			cell.setBorder(Rectangle.NO_BORDER);//设置 不需要边框
			tableHeader.addCell(cell);
			cell = new PdfPCell(new Paragraph("报价单编号 "+"03160564603216613",FontData));
			cell.setBorder(Rectangle.NO_BORDER);    
			tableHeader.addCell(cell);    
			cell=new PdfPCell(new Paragraph("客户名称 "+"北京龙辉鞋业",FontData));          
			cell.setBorder(Rectangle.NO_BORDER);        
			tableHeader.addCell(cell);        
			cell=new PdfPCell(new Paragraph("    销售隶属 "+"03160564603216613",FontData));              
			cell.setBorder(Rectangle.NO_BORDER);            
			tableHeader.addCell(cell);            
			cell=new PdfPCell(new Paragraph("        电话 "+"024-265469846",FontData));                 
			cell.setBorder(Rectangle.NO_BORDER);                
			tableHeader.addCell(cell);                
			cell=new PdfPCell(new Paragraph("     订单时间 "+"2010-10-13",FontData));                  
			cell.setBorder(Rectangle.NO_BORDER);                  
			tableHeader.setSpacingBefore(30f);   //设置表上边的距离               
			tableHeader.addCell(cell);    
			float[] widths = {0.5f,0.5f};    //设置列的宽度  百分比的形式    
			tableHeader.setWidths(widths);    
			tableHeader.setSpacingBefore(15f);     
			document.add(tableHeader);        
			PdfPTable table = new PdfPTable(7);    
			cell=new  PdfPCell(new  Paragraph("商 品 编号",FontTableHeader));     
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);           //居中显示    
			table.addCell(cell);
			cell=new  PdfPCell(new  Paragraph("商 品名称",FontTableHeader));     
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell(cell);    
			cell=new  PdfPCell(new  Paragraph("数量",FontTableHeader));     
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell(cell);    
			cell=new  PdfPCell(new  Paragraph("单位",FontTableHeader));     
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell(cell);    
			cell=new  PdfPCell(new  Paragraph("单价(元)",FontTableHeader));     
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell(cell);    
			cell=new  PdfPCell(new  Paragraph("折 扣(%)",FontTableHeader));
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell(cell);    
			cell=new  PdfPCell(new  Paragraph("公式",FontTableHeader));     
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);    
			table.addCell(cell);    
			cell.setFixedHeight(20f);    
			for(int i=0;i<=100;i++){    
				cell=new  PdfPCell(new Paragraph("205464616543165",FontTable));    
				table.addCell(cell);    
				cell=new  PdfPCell(new  Paragraph("笔 记本电脑",FontTable));    
				table.addCell(cell);    
				cell=new PdfPCell(new Paragraph("234",FontTable));    
				table.addCell(cell);    
				cell=new PdfPCell(new Paragraph("台",FontTable));    
				table.addCell(cell);
				cell=new PdfPCell(new Paragraph("5000",FontTable));    
				table.addCell(cell);
				cell=new PdfPCell(new Paragraph("80%",FontTable));    
				table.addCell(cell);    
				cell=new PdfPCell(new Paragraph("aefwa",FontTable));    
				table.addCell(cell);    
				table.setHeaderRows(1);            //每页都设置表头    
				}    
			float[]  width  =  {0.2f,  0.2f, 0.1f,0.1f,0.1f,0.1f,0.2f};    //设置列的宽度  百分比的形式    
			table.setWidths(width);    
			table.setSpacingBefore(15f);            //设置表上边的距离    
			document.add(table);        
			PdfPTable tableBottom = new PdfPTable(2);    
			cell=new  PdfPCell(new  Paragraph("销 售人   "+"王萍",FontData));        
			cell.setBorder(Rectangle.NO_BORDER);      
			tableBottom.addCell(cell);      
			cell=new  PdfPCell(new  Paragraph("销 售 编 号 "+"03160564603216613",FontData));      
			cell.setBorder(Rectangle.NO_BORDER);    
			tableBottom.addCell(cell);    
			cell=new PdfPCell(new Paragraph("最近修改人 "+"王萍",FontData));      
			cell.setBorder(Rectangle.NO_BORDER);    
			tableBottom.addCell(cell);    
			cell=new PdfPCell(new Paragraph("客户类型 "+"服务",FontData));      
			cell.setBorder(Rectangle.NO_BORDER);    
			tableBottom.addCell(cell);    
			cell=new PdfPCell(new Paragraph("业务归属人 "+"王萍",FontData));      
			cell.setBorder(Rectangle.NO_BORDER);    
			cell.setColspan(2);    
			tableBottom.addCell(cell);    
			cell=new PdfPCell(new Paragraph("备注:"+    "　相信自己就是要‘自信’就是面对困难、挫折和新的挑战不要折服不要胆怯。面对困难、挫折、挑战只要你肯相信自" +    "己不断努力的付出哪怕你现在的人生是从零开始你都可以做得到。",FontData));       
			cell.setBorder(Rectangle.NO_BORDER);    
			cell.setColspan(2);     
			tableBottom.addCell(cell);
			 tableBottom.setSpacingBefore(15f);             //设置表上边的距离    
			 document.add(tableBottom);    
			 document.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public static void main(String[] args) {
//		test1();
//		test2();
//		test3();
//		test4();
//		test5();
//		test6();
//		test7();
//		test8();
//		test9();
//		test10();
//		test11();
//		test12();
//		test13();
//		test14();
//		test15();
		Phrase_();
	}

	public static void Phrase_(){
		//创建文本  
        Document document = new Document();  
         try {  
             //写入到输出流中  
             PdfWriter.getInstance(document, new FileOutputStream("d:\\Phrase.pdf"));  
             //打开文本  
             document.open();  
             //定义文本块  
             Chunk chunk = new Chunk("This is a sentence ");  
             //设置行间距  
             Phrase phrase = new Phrase(50);  
             //添加短句  
             phrase.add(chunk);  
             phrase.add(chunk);  
             phrase.add(chunk);  
             phrase.add(chunk);  
             phrase.add(chunk);  
             phrase.add(chunk);  
             //添加短句  
             document.add(phrase);  
             //关闭文本  
             document.close();  
  
         } catch (DocumentException e) {  
             e.printStackTrace();  
         } catch (FileNotFoundException e) {  
             e.printStackTrace();  
         }  
	}
	
	
}
